﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mogre;

namespace WastedMechanics
{
    public class AnimGroup
    {
        public List<AnimStatePart> AnimStates;
        public List<ushort> Mask;
        public List<string> BoneNames;
        uint NumBones;

        public AnimGroup(Character character)
        {
            NumBones = character.BodyEntity.Skeleton.NumBones;
            BoneNames = new List<string>();
            Mask = new List<ushort>();
            AnimStates = new List<AnimStatePart>();
        }

        public void AddState(AnimStatePart state)
        {
            AnimStates.Add(state);
            state.AnimationState.CreateBlendMask(NumBones, 0);
            foreach (ushort maskBone in Mask)
                state.AnimationState.SetBlendMaskEntry(maskBone, 1);
            state.AffectedGroupsCount++;
        }

        public void ResetBlendMasks()
        {
            foreach (AnimStatePart part in AnimStates)
            {                
                part.AnimationState.CreateBlendMask(NumBones, 0);
                foreach (ushort maskBone in Mask)
                    part.AnimationState.SetBlendMaskEntry(maskBone, 1);                
            } 
        }

        public void AddBone(Bone bone)
        {
            Mask.Add(bone.Handle);
            BoneNames.Add(bone.Name);
        }
    }
}
